/**
 * 
 */
package pt.mleiria.network.pool;

import java.net.Socket;

import org.apache.commons.pool.PoolableObjectFactory;

import pt.mleiria.network.utils.ServerConstants;

/**
 * @author NB13712
 *
 */
public class PoolableSocketFactory implements PoolableObjectFactory{

	public PoolableSocketFactory() {
		super();
	}
	public Object makeObject() throws Exception {
		System.out.println("Making Socket Object...");
		final Socket clientSocket = new Socket(ServerConstants.HOST, ServerConstants.PORT);
		return clientSocket;
	}

	public void destroyObject(Object obj) throws Exception {
		System.out.println("Destroying Socket Object...");
		if(obj instanceof Socket){
			((Socket)obj).close();
		}
		
	}

	public boolean validateObject(Object obj) {
		System.out.println("Validating Socket Object...");
		if(obj instanceof Socket){
			return ((Socket)obj).isBound();
		}
		return false;
	}

	public void activateObject(Object obj) throws Exception {
	}

	public void passivateObject(Object obj) throws Exception {
	}

}
